package com.sinosoft.front.web;

import java.rmi.RemoteException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sinosoft.front.dto.common.xsd.IinsuranceExtensionEhm;
import com.sinosoft.front.dto.common.xsd.TxInsuranceRequestEhm;
import com.sinosoft.front.dto.common.xsd.TxInsuranceRequestExtensionEhm;
import com.sinosoft.front.dto.provisionalTmpSave.xsd.ApplicantTmp;
import com.sinosoft.front.dto.provisionalTmpSave.xsd.MainTmp;
import com.sinosoft.front.dto.xsd.ProvisionalTmpSaveRequest;
import com.sinosoft.front.dto.xsd.ProvisionalTmpSaveResponse;
import com.sinosoft.front.service.ProvisionalTmpSaveServicePortType;
import com.sinosoft.front.service.ProvisionalTmpSaveServicePortTypeProxy;

@Controller
public class VehicleModelQueryAction {

	@RequestMapping(value = "saveVehicleModelQueryAction")
	public String saveVehicleModelQueryAction(HttpServletRequest httpRequest,ApplicantTmp applicantTmp,
			Model model) {
		// 调用服务器端方法 订单暂存服务
		
		ProvisionalTmpSaveServicePortTypeProxy proxy = new ProvisionalTmpSaveServicePortTypeProxy();
		proxy.setEndpoint("http://proxy.tuxing51.com/frontServiceCenter/services/ProvisionalTmpSaveService?wsdl");
		ProvisionalTmpSaveServicePortType portType = proxy.getProvisionalTmpSaveServicePortType();

		//定义请求头
		//VehicleModelQueryRequest request = new VehicleModelQueryRequest();
		ProvisionalTmpSaveRequest tmpSaveRequest = new ProvisionalTmpSaveRequest();
		
		
		// 请求头信息
		TxInsuranceRequestEhm requestEhm = new TxInsuranceRequestEhm();
		requestEhm.setTransExeDate("2017-3-17");
		requestEhm.setTransExeTime("12:24:34");
		tmpSaveRequest.setTxInsuranceRequestEhm(requestEhm);

		requestEhm.setIinsuranceExtensionEhm(new IinsuranceExtensionEhm());

		// 请求扩展信息
		TxInsuranceRequestExtensionEhm extensionEhm = new TxInsuranceRequestExtensionEhm();
		extensionEhm.setOperator("HN1_Test");
		extensionEhm.setOperatorKey("123456");
		tmpSaveRequest.setTxInsuranceRequestExtensionEhm(extensionEhm);
		
		//暂存主信息
		MainTmp mainTmp = new MainTmp();
		mainTmp.setPolicySort("HN1");
		mainTmp.setBusinessNature("2");
		mainTmp.setAgentCode("1234567899");
		//mainTmp.setFranchiserCode("");没找着参数，稍后再传
		//mainTmp.setRelationFlag("");没找着参数，稍后再传
//        request.setPolicySort("HN1");
//        request.setBusinessNature("2");
//		request.setAgentCode("1234567899");
//		request.setFranchiserCode("");
//		request.setRelationFlag("");
		tmpSaveRequest.setMainTmp(mainTmp);
		
		
		//保存提交表单数据
		tmpSaveRequest.setApplicantTmp(applicantTmp);
		// 入口参数
//		request.setPolicySort("HN1");
//		request.setAgentCode("1234567899");
//		request.setFranchiserCode("4105979018");
//		request.setLocalModelQueryFlag("1");
//		request.setStandardName("B");
//		request.setCityAreaCode("410100");

		// 获取返回信息
		ProvisionalTmpSaveResponse tmpSaveResponse = null;
		try {
			tmpSaveResponse = portType.saveProvisionalTmp(tmpSaveRequest);
//			response = portType.queryVehicleModel(request);
		} catch (RemoteException e) {
			// 处理异常
			e.printStackTrace();
			httpRequest.setAttribute("error", "系统异常，请重新输入");
			return "index";
		}
		System.out.println(tmpSaveResponse.getTxInsuranceResponseEhm()
				.getTransResultEhm().getResultCode());
		System.out.println(tmpSaveResponse.getTxInsuranceResponseEhm()
				.getTransResultEhm().getResultInfoDesc());
		System.out.println(tmpSaveResponse.getTxInsuranceResponseEhm()
				.getTransResultEhm().getErrorNo());
		return "index";

	}
}
